extends Panel

var json
var type1 = ""

func on_add(type):
	type1 = type
	match type:
		"game":
			$VBoxContainer/AddType.text = "添加游戏"
		"anime":
			$VBoxContainer/AddType.text = "添加动画"
		"book":
			$VBoxContainer/AddType.text = "添加书本"
		"film":
			$VBoxContainer/AddType.text = "添加电影"
		"tv":
			$VBoxContainer/AddType.text = "添加电视剧"
		"music":
			$VBoxContainer/AddType.text = "添加音乐"
	self.show()
	
func _on_Cancel_pressed():
	self.hide()
	pass 


func _on_Add_pressed():
	var zp_name = $VBoxContainer/Name.text
	var zp_info = $VBoxContainer/ZpInfo.text
	match type1:
		"game":
			if Global.dataJson.has("game") == false:
				Global.dataJson.game = {zp_name:{"info":zp_info,"status":""}}
			else:
				Global.dataJson.game[zp_name] = {"info":zp_info,"status":""}
		"anime":
			if Global.dataJson.has("anime") == false:
				Global.dataJson.anime = {zp_name:{"info":zp_info,"status":""}}
			else:
				Global.dataJson.anime[zp_name] = {"info":zp_info,"status":""}
		"book":
			if Global.dataJson.has("book") == false:
				Global.dataJson.book = {zp_name:{"info":zp_info,"status":""}}
			else:
				Global.dataJson.book[zp_name] = {"info":zp_info,"status":""}
		"film":
			if Global.dataJson.has("film") == false:
				Global.dataJson.film = {zp_name:{"info":zp_info,"status":""}}
			else:
				Global.dataJson.film[zp_name] = {"info":zp_info,"status":""}
		"tv":
			if Global.dataJson.has("tv") == false:
				Global.dataJson.tv = {zp_name:{"info":zp_info,"status":""}}
			else:
				Global.dataJson.tv[zp_name] = {"info":zp_info,"status":""}
		"music":
			if Global.dataJson.has("music") == false:
				Global.dataJson.music = {zp_name:{"info":zp_info,"status":""}}
			else:
				Global.dataJson.music[zp_name] = {"info":zp_info,"status":""}
	var file = File.new()
	if OS.get_name() == "Android":
		if Global.android_save_mode == Global.AndroidSaveMode.user:
			file.open("user://data.json",File.WRITE_READ)
			file.store_string(to_json(Global.dataJson))
			file.close()
		elif Global.android_save_mode == Global.AndroidSaveMode.sdcard:
			file.open(Global.android_sdcard_path,File.WRITE_READ)
			file.store_string(to_json(Global.dataJson))
			file.close()
	else:
		if Global.save_path_mode == Global.SavePathMode.exe:
			file.open(OS.get_executable_path().get_base_dir() + "/data.json",File.WRITE_READ)
			file.store_string(to_json(Global.dataJson))
			file.close()
		elif Global.save_path_mode == Global.SavePathMode.user:
			file.open("user://data.json",File.WRITE_READ)
			file.store_string(to_json(Global.dataJson))
			file.close()
	pass
